package object.obj2D.tree;

import javax.microedition.khronos.opengles.GL10;

import object.obj2D.graphics.TexSquare;
import object.obj2D.graphics.Texture;
import system.Device;
import system.Graphics;

public class Tree {
	
	private int m_iWidth;
	private int m_iHeight;
	private TexSquare m_square;
	private Texture m_texture;
	private int m_textureID;
	private float m_distanceZ;
	private float m_angle;
	private float m_distanceY;
	private GL10 gl;
	
	public Tree(int resID, int width, int height)
	{
		m_iWidth = width;
		m_iHeight = height;
		m_texture = new Texture();
		m_textureID = m_texture.initTexture(resID);
		Device.DisableScaleFactor();
		m_square = new TexSquare(m_iWidth, m_iHeight);
		Device.EnableScaleFactor();
		
		gl = Graphics.GetGraphics();
	}
	
	public Tree(int width, int height)
	{
		m_iWidth = width;
		m_iHeight = height;
		m_texture = new Texture();
		Device.DisableScaleFactor();
		m_square = new TexSquare(m_iWidth, m_iHeight);
		Device.EnableScaleFactor();
		
		gl = Graphics.GetGraphics();
	}
	
	public void SetTexID(int texID)
	{
		m_textureID = texID;
	}
	
	
	public void SetDistanceY(float distanceY)
	{
		m_distanceY = distanceY;
	}
	
	public void SetDistanceZ(float distanceZ)
	{
		m_distanceZ = distanceZ;
	}
	
	public void SetAngle(float angle)
	{
		m_angle = angle;
	}
	
	public void Render()
	{
		gl.glDisable(GL10.GL_DEPTH_TEST);
		m_texture.loadTexture(m_textureID);		
		gl.glMatrixMode(GL10.GL_MODELVIEW);
		gl.glPushMatrix();
		gl.glLoadIdentity();
		gl.glRotatef(m_angle, 0, 1.0f, 0);
		gl.glTranslatef(0, -m_distanceY, m_distanceZ);
		gl.glRotatef(180, 0, 1.0f, 0);
		m_square.Render();	
		gl.glRotatef(-90, 0, 1.0f, 0);
		m_square.Render();
		gl.glPopMatrix();
		gl.glEnable(GL10.GL_DEPTH_TEST);
	}
}
